package com.zhaoyue.study.netty.socket;

import com.zhaoyue.study.domain.OrderDO;
import com.zhaoyue.study.dto.ResultDTO;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;

import java.util.Date;

/**
 * @author zhaoyue
 * @description:
 * @create 2018-11-13 下午5:13
 **/
public class SubReqClientHandler extends ChannelInboundHandlerAdapter {


    @Override
    public void channelActive(ChannelHandlerContext ctx) throws Exception {
        OrderDO orderDO = new OrderDO()
                .setId(1)
                .setOrderId("10000")
                .setPrice(1000)
                .setCreateTime(new Date());
        ctx.writeAndFlush(orderDO);
    }

    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
        ResultDTO resultDTO = (ResultDTO) msg;
        System.out.println(resultDTO.getCode());
        System.out.println(resultDTO.getMsg());
    }

    @Override
    public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
        super.channelReadComplete(ctx);
    }

    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
        super.exceptionCaught(ctx, cause);
    }
}
